<!-- 搜索界面 -->
<template>
	<view>
		<view class="search-top">
			<view class="search-input-box">
				<view class="search-input">
					<u-icon name="search" color="#2ba4f7" size="32" class="icon" style="margin: 0 30rpx;"></u-icon>
					<input type="text" placeholder="请输入商品名称搜索" v-model="search">
				</view>
			</view>
			<view class="search-btn" @click="toSearch()">搜索</view>
		</view>
		<view class="search-data">
			<scroll-view class="scroll-view" scroll-y>
				<view v-for="(item,index) in orderList" :key="index">
					<!-- 订单管理基础模板 -->
					<view class="order-manage-card">
						<view class="top" @click='toOrderDeatil(item)'>
							<view class="top-number">
								<text>订单编号： </text><text class="number"> {{item.order_id}}</text>
							</view>
							<view class="top-state">
								<text>{{item.deliver_state == 0 ? '待发货' : '已发货'}}</text>
							</view>
						</view>
						<view class="content" @click='toOrderDeatil(item)'>
							<goods-info :data="item"></goods-info>
						</view>
						<view class="bottom">
							<view class="bottom-left">
								<text>{{item.pay_time | filterDate)}}</text>
							</view>
							<view class="bottom-right" @click='toOrderDeatil(item)'>
								<button type="default" plain="true">查看详情</button>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<tui-no-data imgUrl="https://sbb-sbb.oss-cn-shenzhen.aliyuncs.com/Open_source_project/mine/empty_bg.png" v-if="noData1">暂无相关数据</tui-no-data>
			<view class="bootom-box">
				<load-more :visible="loadMore "></load-more>
				<om-nomore :visible="noMoreFlag && !noData1" bgcolor="#f9f9f9"></om-nomore>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search: '',
				orderList:[],
				currentPage: 1,       //分页
				total: 0,             //数据总数
				loadMore: false,      //数据加载中
				noMoreFlag: false,    //没有更多数据了
				noData1: false,       //没有数据
			};
		},
		watch:{
			search(){
				this.clear()
			},
		},
		methods: {
			//搜索
			toSearch() {
				if (!this.search) return this.$tip.toast('请输入商品名称！');
				this.loadMore = true;
				this.$http.post('/api/auth/order/countryBusinGoodList',{businId: this.$store.state.userInfo.id,deliverState: -1,currentPage: this.currentPage,title: this.search}).then(res => {
					this.loadMore = false;
					this.total = res.data.total;
					if(this.total == 0) return this.noData1 = true;
					this.orderList = this.orderList.concat(res.data.rows)
				})
			},
			//跳转订单详情
			toOrderDeatil(item){
				this.$u.route('pages/home/order-manage/order-detail/order-detail');
				//先跳转页面，在通过嵌套$emit传数据
				uni.$once('need',() => {
					uni.$emit('detail',{
						busin_id: item.busin_id,
						order_id: item.order_id
					})
				})
			},
			clear(){
				this.orderList = [];
				this.noData1 = false;
				this.noMoreFlag = false;
				this.currentPage = 1;
				this.total = 0
			},
		},
		onReachBottom(){
			if(this.total == this.orderList.length) return this.noMoreFlag = true;
			this.currentPage++;
			this.toSearch()
		}
	}
</script>

<style lang="scss" scoped>
	.search-top {
		display: flex;
		align-items: center;

		.search-input-box {
			width: 80%;

			.search-input {
				display: flex;
				margin: 0 30rpx;
				height: 70rpx;
				border: 1px solid #2ba4f7;
				border-radius: 40rpx;
				background-color: #ffffff;

				input {
					height: 66rpx;
					font-size: 15px;
				}
			}
		}

		.search-btn {
			width: 16%;
			height: 56rpx;
			line-height: 56rpx;
			text-align: center;
			color: #fff;
			border-radius: 30rpx;
			background-color: #2ba4f7;
		}
	}

	.search-data {
		height: calc(100% - 124rpx);

		.scroll-view {
			height: 100%;
		}
	}

	.order-manage-card {
		margin: 30rpx 20rpx;
		padding: 30rpx 20rpx;
		height: 380rpx;
		border-radius: 20rpx;
		background-color: #fff;

		.top {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 0;
			font-size: 13px;

			.top-number {
				.number {
					margin-left: 10rpx;
					font-size: 15px;
					font-weight: 700;
				}
			}

			.top-state {
				color: #2ba4f7;
			}

		}

		.content {
			margin: 30rpx 0;

			.content-foot {
				display: flex;
				flex-direction: row-reverse;
				align-items: center;

				text {
					color: #aaa7a0;
				}

				.total {
					margin-left: 10rpx;
					color: #000;
					font-size: 16px;
					font-weight: 700;
				}

			}

		}

		.bottom {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.bottom-left {
				// margin-left: 20rpx;
				color: #bebebe;
			}

			.bottom-right {
				button {
					margin-left: 20rpx;
					width: 200rpx;
					height: 60rpx;
					font-size: 14px;
					line-height: 60rpx;
					color: #2ba4f7;
					border: none;
					border-radius: 40rpx;
					background-color: #f7f7f7;
				}
			}
		}
	}

	.bootom-box{
		height: 160rpx;
	}
</style>
